﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Oragon.Architecture.Data.SqlBuilder
{
	/// <summary>
	/// Representa uma coluna
	/// </summary>
	[Serializable]
	public class ColumnItem : ISQLStatement
	{
        public SqlLiteral ColumnExpression { get; set; }
		
		public string Alias { get; set; }


		public ColumnItem() { }

        public ColumnItem(SqlLiteral fullExpression)
		{
			this.ColumnExpression = fullExpression;
			this.Alias = null;
		}

        public ColumnItem(SqlLiteral columnExpression, string alias)
		{
			this.ColumnExpression = columnExpression;
			this.Alias = alias;
		}
		

		
		/// <summary>
		/// Retorna o SQL referente ao segmento
		/// </summary>
		/// <returns></returns>
		public string ToSQL()
		{
			if(this.Alias == null)
				return this.ColumnExpression.ToSQL();
			else
                return string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} as {1}", this.ColumnExpression.ToSQL(), this.Alias);
		}
	}
}
